<?php
namespace app\models;

use Yii;
use common\models\Sms;
/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

/**
 * Description of VerifyCode
 *
 * @author Administrator
 */
class VerifyCode extends Sms{
    //put your code here
        /**
     *sendCode($tel) 发送验证码给手机
     * author:sunjian
     * time:2015年12月19日11:54:30
     * return 
     *      */
    public function sendCode($tel) {
        $code=rand(1000,9999);
        $data['code']=$code;
        $data['phone']=$tel;
        $data['time']=time();
        Yii::$app->session->set("code",$data);
        
        $content="您此次操作的验证码是".$code.",请妥善保管【宁网科技】";
        $this->main($tel, $content);
        return ;
    }
    
    /**
    *verifycode($code) 验证验证码
     * author:sunjian
     * time:2015年12月19日12:04:26
     * return <bool>
     *      */
    
    public function verifycode($code,$phone){
        $data=Yii::$app->session->get('code');
        if($data['time']<time()-60*5){
           
            return false;
        }
        if($code==$data['code']&&$phone==$data['phone']){
            
            return TRUE;
        }else{
            return false;
        }
    }
        /**
        *sendPassword($password,$phone) 创建子账号时，发送初始密码给手机
        * author:sunjian
        * time:2015年12月19日11:54:30
        * return 
        *      */
        public function sendPassword($password,$phone) {
        $content="您的初始密码为".$password.",请尽快登录找化妆品网修改密码【宁网科技】";
        $this->main($phone, $content);
    }
}
